Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for Netlify Edge Functions #2866

Merged
merged 13 commits into from
Apr 19, 2022

Conversation

ascorbic
Copy link
Contributor

This PR adds a Remix adapter for the beta release of Netlify Edge Functions. It is implemented as a package @remix-run/netlify-edge and uses the Deno runtime with some small but important changes. Most significantly, this adapter bundles all of the generated server code (except the adapter itself), and by default expects that user code will use regular node-style imports rather than URL imports as expected by Deno. The generated server code is Deno-compatible, and can be used directly as a Netlify Edge Function. It is emitted into .netlify/edge-functions/server.js. It also generates a manifest in .netlify/edge-functions/manifest.json. The Deno runtime code is currently inlined inside the package, because it isn't published anywhere at present.

This PR also adds some tooling to make life easier when working on Deno and Node code in the same repo. This includes defining deno.enablePaths in the VS Code settings, so that it only runs on Deno code, and adding an import map so that Deno code that uses bare imports (such as the imports of build) works as expected.

It extends the default Netlify template, adding a remix.init script that asks if the user want to use Edge Functions, and setting the project up accordingly.

Closes: #

  • Docs
  • Tests

@chaance chaance merged commit a480c9a into remix-run:tender-stonebraker Apr 19, 2022
Comment on lines +357 to +358
config.serverBuildTarget === "deno" ||
config.serverBuildTarget === "netlify-edge"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified to

    ["deno", "netlify-edge"].includes(config.serverBuildTarget]

SessionData,
SessionIdStorageStrategy,
SessionStorage,
} from "https://esm.sh/@remix-run/server-runtime@1.4.1";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep this or change it to something like we have in the remix-deno package?

Suggested change
} from "https://esm.sh/@remix-run/server-runtime@1.4.1";
} from "https://esm.sh/@remix-run/server-runtime?pin=v77";

isSession,
json,
redirect,
} from "https://esm.sh/@remix-run/server-runtime@1.4.1";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} from "https://esm.sh/@remix-run/server-runtime@1.4.1";
} from "https://esm.sh/@remix-run/server-runtime?pin=v77";

Comment on lines +1 to +2
import type { ServerBuild } from "https://esm.sh/@remix-run/server-runtime@1.3.5?pin=v77";
import { createRequestHandler as createRemixRequestHandler } from "https://esm.sh/@remix-run/server-runtime@1.3.5?pin=v77";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are referencing older versions.

We should at least update to latest version

Suggested change
import type { ServerBuild } from "https://esm.sh/@remix-run/server-runtime@1.3.5?pin=v77";
import { createRequestHandler as createRemixRequestHandler } from "https://esm.sh/@remix-run/server-runtime@1.3.5?pin=v77";
import type { ServerBuild } from "https://esm.sh/@remix-run/server-runtime@1.4.1?pin=v77";
import { createRequestHandler as createRemixRequestHandler } from "https://esm.sh/@remix-run/server-runtime@1.4.1?pin=v77";

Or remove version number all together

Suggested change
import type { ServerBuild } from "https://esm.sh/@remix-run/server-runtime@1.3.5?pin=v77";
import { createRequestHandler as createRemixRequestHandler } from "https://esm.sh/@remix-run/server-runtime@1.3.5?pin=v77";
import type { ServerBuild } from "https://esm.sh/@remix-run/server-runtime?pin=v77";
import { createRequestHandler as createRemixRequestHandler } from "https://esm.sh/@remix-run/server-runtime?pin=v77";

@@ -0,0 +1,917 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably delete this file, as none of the templates have one

"index.js"
],
"peerDependencies": {
"@remix-run/server-runtime": "*"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably go into dependencies I think? 🤔

@@ -1,4 +1,4 @@
import type { EntryContext } from "@remix-run/node";
import type { EntryContext } from "@remix-run/server-runtime";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should only be the case when choosing for "Netlify Edge Functions", so this file should be overridden by remix.init? 🤔

@@ -1,4 +1,4 @@
import type { MetaFunction } from "@remix-run/node";
import type { MetaFunction } from "@remix-run/server-runtime";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should only be the case when choosing for "Netlify Edge Functions", so this file should be overridden by remix.init? 🤔

@@ -10,7 +10,7 @@
"start": "cross-env NODE_ENV=production netlify dev"
},
"dependencies": {
"@netlify/functions": "^0.10.0",
"@netlify/functions": "latest",
"@remix-run/netlify": "*",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably replace this with @remix-run/netlify-edge when choosing for "Netlify Edge Functions" in remix.init

@@ -10,7 +10,7 @@
"start": "cross-env NODE_ENV=production netlify dev"
},
"dependencies": {
"@netlify/functions": "^0.10.0",
"@netlify/functions": "latest",
"@remix-run/netlify": "*",
"@remix-run/node": "*",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably replace this with @remix-run/server-runtime when choosing for "Netlify Edge Functions" in remix.init

@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version v0.0.0-nightly-a9f2dde-20220426 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version v0.0.0-nightly-cc69c1b-20220427 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version v1.4.2-pre.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version v1.4.2 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants